﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;

namespace MySQLStudio.Common.Data
{
    public class DbDataTypeCollection : IList<DbDataType>
    {
        private List<DbDataType> dataTypes = new List<DbDataType>();

        #region IList<DbDataType> Members

        public int IndexOf(DbDataType item)
        {
            return this.dataTypes.IndexOf(item);
        }

        public void Insert(int index, DbDataType item)
        {
            this.Insert(index, item);
        }

        public void RemoveAt(int index)
        {
            this.RemoveAt(index);
        }

        public DbDataType this[int index]
        {
            get
            {
                return this.dataTypes[index];
            }
            set
            {
                this.dataTypes[index] = value;
            }
        }

        #endregion

        #region ICollection<DbDataType> Members

        public void Add(DbDataType item)
        {
            this.dataTypes.Add(item);
        }

        public void Clear()
        {
            this.dataTypes.Clear();
        }

        public bool Contains(DbDataType item)
        {
            return this.dataTypes.Contains(item);
        }

        public void CopyTo(DbDataType[] array, int arrayIndex)
        {
            this.dataTypes.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get
            {
                return this.dataTypes.Count;
            }
        }

        public bool IsReadOnly
        {
            get
            {
                return false;
            }
        }

        public bool Remove(DbDataType item)
        {
            return this.dataTypes.Remove(item);
        }

        #endregion

        #region IEnumerable<DbDataType> Members

        public IEnumerator<DbDataType> GetEnumerator()
        {
            return this.dataTypes.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.dataTypes.GetEnumerator();
        }

        #endregion

        public void Sort()
        {
            this.dataTypes.Sort();
        }

        public StringCollection DataTypes
        {
            get
            {
                StringCollection collection = new StringCollection();

                foreach (DbDataType dataType in this.dataTypes)
                {
                    collection.Add(dataType.Name);
                }

                return collection;
            }
        }
    }
}
